package com.fxsh168.server.adapters;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.fxsh168.server.entitys.WholeOrderEntity;
import com.fxsh168.server.R;

import java.util.List;

public class WholeOrderAdapter extends BaseAdapter {
    private Context context;
    private List<WholeOrderEntity.DataBean> wholeOrderDataList;

    public WholeOrderAdapter(Context context, List<WholeOrderEntity.DataBean> wholeOrderDataList) {
        this.context = context;
        this.wholeOrderDataList = wholeOrderDataList;
    }

    @Override
    public int getCount() {
        return wholeOrderDataList.size();
    }

    @Override
    public Object getItem(int position) {
        return wholeOrderDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.orderitem, null);
            viewHolder = new ViewHolder();
            viewHolder.start = (TextView) convertView.findViewById(R.id.start);
            viewHolder.end = (TextView) convertView.findViewById(R.id.end);
            viewHolder.startTime = (TextView) convertView.findViewById(R.id.startTime);
            viewHolder.state = (TextView) convertView.findViewById(R.id.state);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (wholeOrderDataList.size() > 0) {
            WholeOrderEntity.DataBean wholeOrderData = wholeOrderDataList.get(position);
            String ridc = wholeOrderData.getRid().toString();
            String statusc = wholeOrderData.getStatus().toString().trim();
            if (!TextUtils.isEmpty(statusc)) {
                if (statusc.equals("3")) {
                    viewHolder.state.setText("正在进行");
                } else if (statusc.equals("4")) {
                    viewHolder.state.setText("已完成");
                } else if (statusc.equals("5")) {
                    viewHolder.state.setText("待支付");
                } else if (statusc.equals("6")) {
                    viewHolder.state.setText("行程中");
                } else if (statusc.equals("7")) {
                    viewHolder.state.setText("待评价");
                } else if (statusc.equals("9")) {
                    viewHolder.state.setText("已取消");
                }
            }
            viewHolder.startTime.setText(wholeOrderData.getGotime().toString().trim());
            viewHolder.start.setText(wholeOrderData.getAddresses().toString().trim());
            viewHolder.end.setText(wholeOrderData.getDown().toString().trim());

        }
        return convertView;
    }

    class ViewHolder {
        TextView start, end, startTime, state;
    }
}
